<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class template_edit extends Page
{
       public $edType = null;
       public $imgBack = null;
       public $btnCancel = null;
       public $btnUpdate = null;
       public $Image3 = null;
       public $hiddenTempId = null;
       public $memoComments = null;
       public $lblComments = null;
       public $edDescription = null;
       public $lblDescription = null;
       public $cmbTemplateType = null;
       public $lblTemplateType = null;
       public $edTemplateNo = null;
       public $lblTemplateNo = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnCancelClick($sender, $params)
       {
       redirect('template_list.php?template_id='.$this->hiddenTempId->getValue());


       }

       function btnUpdateClick($sender, $params)
       {

       $style_id = $this->cmbTemplateType->getItemIndex();
       $result_style = mysql_query("SELECT value FROM lookup_vehicle_tbl WHERE id='".$style_id."'") or die("ERROR STYLE ".mysql_error());
       $row_style = mysql_fetch_array($result_style);
       $style_name = $row_style['value'];

       mysql_query("update template_tbl set
       comments = '".$this->memoComments->Text."'
       where template_id ='".$this->hiddenTempId->getValue()."'")or die ("UPDATE TEMPLATE-".mysql_error());
       redirect('template_list.php?template_id='.$this->hiddenTempId->getValue());

       //template_type = '".$this->cmbTemplateType->getItemIndex()."',

       }

       function template_editCreate($sender, $params)
       {
       $template_id = $_GET['template_id'];
       $this->hiddenTempId->setValue($template_id);
       $this->imgBack->setLink('template_list.php?template_id='.$this->hiddenTempId->getValue());

       $query_template = "select * from template_tbl where template_id='".$this->hiddenTempId->getValue()."'";
       $result_template_show = mysql_query($query_template)or die("SELECT TEMPLATE - " . mysql_error());
       $row_template = mysql_fetch_array($result_template_show);

       $this->edTemplateNo->Text = $row_template['template_num'];
       $this->edDescription->Text = $row_template['description'];
       $this->memoComments->Text = $row_template['comments'];

       $this->edType->Text = $row_template['template_type'];
       $this->cmbTemplateType->ItemIndex=$row_template['template_type'];
       $result_type = mysql_query("select * from lookup_template_tbl where category='types'");

       while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbTemplateType->AddItem($row_type['value'], null, $row_type['id']);
        }
       }

}

global $application;

global $template_edit;

//Creates the form
$template_edit=new template_edit($application);

//Read from resource file
$template_edit->loadResource(__FILE__);

//Shows the form
$template_edit->show();

?>